package com.tledu.email.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tledu.common.annotation.Log;
import com.tledu.common.core.controller.BaseController;
import com.tledu.common.core.domain.AjaxResult;
import com.tledu.common.enums.BusinessType;
import com.tledu.email.domain.EmailBin;
import com.tledu.email.service.IEmailBinService;
import com.tledu.common.utils.poi.ExcelUtil;
import com.tledu.common.core.page.TableDataInfo;

/**
 * 垃圾箱Controller
 *
 * @author ruoyi
 * @date 2024-09-02
 */
@RestController
@RequestMapping("/email/bin")
public class EmailBinController extends BaseController {
    @Autowired
    private IEmailBinService emailBinService;

    // 还原操作，实际上是更新
    @PreAuthorize("@ss.hasPermi('email:bin:edit')")
    @Log(title = "逻辑更新", businessType = BusinessType.UPDATE)
    @PutMapping("/restore/{ids}")
    public AjaxResult updateByChangeSymbol(@PathVariable Long[] ids) {
        return toAjax(emailBinService.updateByChangeSymbol(ids));
    }

    // 逻辑删除，实际上的更新操作
    @PreAuthorize("@ss.hasPermi('email:bin:edit')")
    @Log(title = "逻辑删除", businessType = BusinessType.UPDATE)
    @PutMapping("/update/{ids}")
    public AjaxResult updateSymbol(@PathVariable Long[] ids) {
        return toAjax(emailBinService.updateSymbol(ids));
    }

    // 根据用户查找当前用户的的垃圾箱邮件列表  selectBinByCondtion
    @PreAuthorize("@ss.hasPermi('email:bin:list')")
    @GetMapping("/condition")
    public TableDataInfo selectBinByCondition(EmailBin emailBin) {
        startPage();
        List<EmailBin> list = emailBinService.selectBinByCondition(emailBin);
        return getDataTable(list);
    }

    // 查找当前用户的垃圾箱邮件列表
    @PreAuthorize("@ss.hasPermi('email:bin:list')")
    @GetMapping("/binList")
    public TableDataInfo selectBinList(EmailBin emailBin) {
        startPage();
        List<EmailBin> list = emailBinService.selectBinList(emailBin);
        return getDataTable(list);
    }

    /**
     * 查询垃圾箱列表
     */
    @PreAuthorize("@ss.hasPermi('email:bin:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmailBin emailBin) {
        startPage();
        List<EmailBin> list = emailBinService.selectEmailBinList(emailBin);
        return getDataTable(list);
    }

    /**
     * 导出垃圾箱列表
     */
    @PreAuthorize("@ss.hasPermi('email:bin:export')")
    @Log(title = "垃圾箱", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmailBin emailBin) {
        List<EmailBin> list = emailBinService.selectEmailBinList(emailBin);
        ExcelUtil<EmailBin> util = new ExcelUtil<EmailBin>(EmailBin.class);
        util.exportExcel(response, list, "垃圾箱数据");
    }

    /**
     * 获取垃圾箱详细信息
     */
    @PreAuthorize("@ss.hasPermi('email:bin:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(emailBinService.selectEmailBinById(id));
    }

    /**
     * 新增垃圾箱
     */
    @PreAuthorize("@ss.hasPermi('email:bin:add')")
    @Log(title = "垃圾箱", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmailBin emailBin) {
        return toAjax(emailBinService.insertEmailBin(emailBin));
    }

    /**
     * 修改垃圾箱
     */
    @PreAuthorize("@ss.hasPermi('email:bin:edit')")
    @Log(title = "垃圾箱", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmailBin emailBin) {
        return toAjax(emailBinService.updateEmailBin(emailBin));
    }

    /**
     * 删除垃圾箱
     */
    @PreAuthorize("@ss.hasPermi('email:bin:remove')")
    @Log(title = "垃圾箱", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(emailBinService.deleteEmailBinByIds(ids));
    }
}
